package mh.modules.mh.controller;

import java.util.Arrays;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import mh.modules.mh.entity.BcEntity;
import mh.modules.mh.service.BcService;
import mh.common.utils.PageUtils;
import mh.common.utils.R;



/**
 * 
 *
 * @author zhongxiang
 * @email 
 * @date 2024-10-23 16:59:34
 */
@RestController
@RequestMapping("mh/bc")
@Slf4j
public class BcController {
    @Autowired
    private BcService bcService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("mh:bc:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bcService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 通过编号信息(详情信息不用权限)
     */
    @RequestMapping("/infobh/{mhBh}")
    public R infoMhBh(@PathVariable("mhBh") String mhBh){
		BcEntity bc = bcService.getByBh(mhBh);
        return R.ok().put("bc", bc);
    }
    /**
     * 通过ID找信息
     */
    @RequestMapping("/info/{bcId}")
    @RequiresPermissions("mh:bc:info")
    public R info(@PathVariable("bcId") Long bcId){
        BcEntity bc = bcService.getById(bcId);

        return R.ok().put("bc", bc);
    }


    /**
     * 保存(病虫信息)
     */
    @RequestMapping("/save")
    @RequiresPermissions("mh:bc:save")
    public R save(@RequestBody BcEntity bc){
        log.info("BcEntity{}",bc);
		boolean save = bcService.saveOrUpdateBc(bc);

        return R.ok("保存结果"+save);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("mh:bc:update")
    public R update(@RequestBody BcEntity bc){
		bcService.updateById(bc);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("mh:bc:delete")
    public R delete(@RequestBody Long[] bcIds){
		bcService.removeByIds(Arrays.asList(bcIds));

        return R.ok();
    }
    /**
     *  首页的3个数据
     */
    @RequestMapping("/zhanshi")
    public R zhanshi(){
        R zhanshi = bcService.zhanshi();
        return R.ok(zhanshi);
    }
    /**
    * 散点图    幼虫数(卵虫数)为y周   总总数为X周
    */
    @RequestMapping("/bcnum")
    public R bcNum(){
        R r = bcService.bcNum();
        return R.ok(r);
    }


}
